package utils

import "golang.org/x/crypto/bcrypt"

// BcryptEncode 生成密码
func BcryptEncode(password string) (string, error) {
	fromPassword, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
	// 将字节切片转字符串
	return string(fromPassword), err
}

// BcryptValidate 验证密码
func BcryptValidate(rawPassword, encodedPassword string) bool {
	return bcrypt.CompareHashAndPassword([]byte(encodedPassword), []byte(rawPassword)) == nil
}
